package cn.wolfcode.rbac.query;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.Collections;
import java.util.List;

@Setter
@Getter
@ToString
public class PageResult {
    //页面结果集类，封装用户请求所查询出来的结果，最终要返回给客户看
    private List data;  //结果集
    private int totalCount;  //总条数

    private int totalPage; //总页数
    private int prevPage;  //上一页
    private int nextPage;  //下一页

    private int currentPage;  //当前页
    private int pageSize;   //每页显示的条数

    //定义全参构造器，能查询出数据的时候调用
    public PageResult(List data,int totalCount,int currentPage,int pageSize){
        this.data=data;
        this.totalCount=totalCount;
        this.currentPage=currentPage;
        this.pageSize=pageSize;

        this.totalPage = totalCount % pageSize ==0 ? totalCount / pageSize : totalCount / pageSize + 1;
        this.prevPage = currentPage>1 ? currentPage - 1 : 1;
        this.nextPage = currentPage<this.totalPage ? currentPage + 1 : this.totalPage;
    }

    //定义缺参构造器，没有查出数据的时候调用
    public PageResult(int currentPage,int pageSize){
        this.data= Collections.EMPTY_LIST;  //设置空集合，因为查不出任何数据
        this.totalCount=0;
        this.currentPage=currentPage;
        this.pageSize=pageSize;
    }
}
